// -----------------配置连接数据库中间件------------
var mongoose = require("mongoose"); //引入mongoose
var moment = require('moment') //引入moment
moment.locale('zh-cn') //设置时区
mongoose.set('useFindAndModify', false)
// 连接数据库
mongoose.connect('mongodb://localhost:27017/warehouse', {useNewUrlParser: true, useUnifiedTopology: true});

 
var db = mongoose.connection;

db.on('error', function callback() { //监听是否有异常
    console.log("Connection error");
});
db.once('open', function callback() { //监听一次打开
    //在这里创建你的模式和模型
    console.log('connected!');
});
//导出mongodb的连接器mongoose
exports.mongoose = mongoose;